﻿using suirui.ZhuMu.Log;
using suirui.ZhuMu.Model;
using suirui.ZhuMu.Entity;
using suirui.ZhuMu.Entity.Entities;
using suirui.ZhuMu.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using System.Web;
using System.Linq.Expressions;
using suirui.ZhuMu.Common.Helper;

namespace suirui.ZhuMu.Repositories
{
    public class RoomRepository : BaseRepository<Room>, IRoomRepository
    {
        public mjgamesContext _context { get; set; }

        public RoomRepository(mjgamesContext context)
            : base(context)
        {
            this._context = context ?? throw new ArgumentNullException(nameof(context));
        }

        public async Task<PageData<Room>> GetRoomList(GetParamsDto paramsDto)
        {
            Expression<Func<Room, bool>> expression = null;
            //if (!string.IsNullOrWhiteSpace(paramsDto.Keyword))
            //    expression = t => t.RoomName .Contains(paramsDto.Keyword) && t.Status != 0;
            //else
            //    expression = t => t.Status != 0;

            var result = await GetPageAsync(expression, t => t.StartTime, paramsDto.PageIndex, paramsDto.PageSize, false);
            return result;
        }

        public async Task<bool> AddRoom(Room health)
        {
            health.RoomId = Snowflake.Instance.nextId();
            health.StartTime = DateTime.Now;
            //health.Status = 1;
            health.Remark += AppConfigration.Configuration["port"];

            return await InsertAsync(health);
        }

        public async Task<bool> UpdateRoom(Room health)
        {
            //var _health = await GetAsync(t => t.RoomId == health.RoomId && t.Status != 0);
            //if (_health != null)
            //{
            //    _health.Remark = health.Remark;
            //    _health.CreateTime = DateTime.Now;

            //    return await UpdateAsync(health);
            //}
            return false;
        }
    }
}
